import { createPinia } from 'pinia'
import { clone } from 'ramda'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'

import type { App } from 'vue'

export function setupStore(app: App<Element>) {
	const resetStore = ({ store }) => {
		const initialState = clone(store.$state)
		store.$reset = () => store.$patch(($state) => Object.assign($state, initialState))
	}
	const pinia = createPinia()
	pinia.use(resetStore)
	pinia.use(piniaPluginPersistedstate)
	app.use(pinia)
}

export * from './modules/app'
export * from './modules/auth'
export * from './modules/counter'
export * from './modules/settings'
